<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>
        <div id="page1"></div>
        <br>
        <div id="page2"></div>
    </div>
    <script>
        // 模块化开发优点：
        //     有自己的私有作用域
        //     避免全局变量的污染
        //     形成闭包全局用变量保存指向
        //     按需加载
        window.onload = function() {
            init();
        }
        function init() {
            console.log(initFb(10))
            var a = document.getElementById('page1')
            var b = document.getElementById('page2')
            a.innerHTML = initFb(10);
            b.innerHTML = initDiv(100);
        }

        var initFb = (function() {
            function fb(n) {
                if(n <= 0) {
                    return 0;
                }
                if(n <= 2) {
                    return 1;
                }
                return fb(n - 1) + fb(n - 2);
            }
            return fb;
        })();

        var initDiv = (function() {
            function div(n) {
                var arr = [];
                for(var i = 0; i <= n; i++) {
                    if(i % 3 === 0 || i % 5 === 0|| i % 7 === 0) {
                        arr.push(i);
                    }
                }
                return arr;
            }
            return div;
        })();

    </script>
</body>
</html>